<?php

namespace App\Admin\Metrics\Examples;

use App\Models\Log\LogUserBrowse;
use App\Models\Log\LogUserCollect;
use App\Models\Search\SearchResult;
use App\Models\User\UserDetail;
use App\Models\User\UserFunds;
use App\Models\User\Users;
use Dcat\Admin\Widgets\Metrics\Round;
use Illuminate\Http\Request;

class Searchlog extends Round
{
    /**
     * 初始化卡片内容
     */
    protected function init()
    {
        parent::init();

        $this->title('搜索数据统计');
        $this->chartLabels(['浏览详情统计', '收藏统计']);
    }

    /**
     * 处理请求
     *
     * @param Request $request
     *
     * @return mixed|void
     */
    public function handle(Request $request)
    {
        switch ($request->get('option')) {
            default:
                $all = SearchResult::count();
                $all =  $all == 0 ? 1 : $all;
                $browse_count = LogUserBrowse::count();
                $collect_count = LogUserCollect::count();
                // 卡片内容
                $this->withContent($browse_count, $collect_count);

                // 图表数据
                $this->withChart([$browse_count / $all * 100, $collect_count / $all * 100]);

                // 总数
                $this->chartTotal('总数', $all);
        }
    }

    /**
     * 设置图表数据.
     *
     * @param array $data
     *
     * @return $this
     */
    public function withChart(array $data)
    {
        return $this->chart([
            'series' => $data,
        ]);
    }

    /**
     * 卡片内容.
     *
     * @param int $finished
     * @param int $pending
     * @param int $rejected
     *
     * @return $this
     */
    public function withContent($pending, $rejected)
    {
        return $this->content(
            <<<HTML
<div class="col-12 d-flex flex-column flex-wrap text-center" style="max-width: 220px">
    

    <div class="chart-info d-flex justify-content-between mb-1">
          <div class="series-info d-flex align-items-center">
              <i class="fa fa-circle-o text-bold-700 text-warning"></i>
              <span class="text-bold-600 ml-50">浏览详情统计</span>
          </div>
          <div class="product-result">
              <span>{$pending}</span>
          </div>
    </div>

     <div class="chart-info d-flex justify-content-between mb-1">
          <div class="series-info d-flex align-items-center">
              <i class="fa fa-circle-o text-bold-700 text-danger"></i>
              <span class="text-bold-600 ml-50">收藏统计</span>
          </div>
          <div class="product-result">
              <span>{$rejected}</span>
          </div>
    </div>
</div>
HTML
        );
    }
}
